﻿using Dapper;
using RightControl.IRepository;
using RightControl.Model;
using System.Linq;
using RightControl.Repository.Product;
using System.Collections.Generic;

namespace RightControl.Repository {
    public class AttrOptionsRepository : BaseRepository<AttrOptions>, IAttrOptionsRepository {

        public IEnumerable<BasicFields> GetBasicFields(string categoryCode) {
            using (var conn = MySqlHelper.GetConnection()) {
                var sql = string.Format(@"SELECT
                                ao.Id,
                             	ef.CategoryCode,
	                            ef.FieldName,
	                            ef.EngFieldNm,
                                ef.FdType,
	                            ao.OptionVal,
                                ts.TransEnglish OptionEngNm, 
                                ao.DhAttrId,
                                ao.DhAttrValueId 
                            FROM
                                exportfields ef
                                LEFT JOIN  attroptions ao ON ef.CategoryCode = ao.CategoryCode  AND ef.EngFieldNm = ao.FieldNm AND ao.Status=0
                                LEFT JOIN translation ts ON ao.OptionVal = ts.OriContent 
                            WHERE
                                ef.CategoryCode = @CategoryCode
                            ORDER BY
                                 ef.CategoryCode, ef.FieldName,ao.SortIndex", categoryCode);
                return conn.Query<BasicFields>(sql, new { CategoryCode = categoryCode });
            }
        }
    }
}
